<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
<html xmlns="http://www.w3.org/1999/xhtml">
<head>
    <!--{include file='comm/header.tpl'}-->
    <title>冰包扫描</title>
    <!--{include file='comm/comm_cal.tpl'}-->
    <script src="/quanliadmin/docroot/js/createreoprt.js"></script>
</head>
<body>
<div class="container">
    <div class="comm_content">
            <div class="search-box">
                <div style="position:relative">
                    <form class="form-inline" id="search_form" onsubmit="return false;">
                        <table>
                            <tbody>
                            <tr>
                                <td>
                                    <span>配送日期：<input type="text"  readonly class="form-control input-sm" style="width:100px" value="<!--{$currentDate|default:''}-->" name="send_date" id="send_date"></span>
                                    <span>
                                       配送城市：
                                        <select id="cityID" name="cityID" class="form-control input-sm" style="width:100px;">
                                            <option value="" selected="">请选择</option>                                            　　
                                        </select>
                                    </span>
                                    <span>
                                        配送站：
                                        <select name="distribution_id" id="distribution_id" class="form-control input-sm" style="width:110px;">
                                            <option value="">请选择</option>
                                        </select>
                                    </span>
                                    <span><input type="button" onclick="Goods.search();" class="btn btn-primary" value="查询"></span>
                                    <span><input type="button" onclick="Goods.load();" class="btn btn-warning" value="重置"></span>
                                </td>
                            </tr>
                            </tbody>
                        </table>
                    </form>
                </div>
            </div>

            <div class="panel panel-default"  >

                <table class="table table-bordered">
                    <thead>
                    <tr>
                        <th width="100" style="text-align: center;">配送站</th>
                        <th width="100" style="text-align: center;">已上车蛋糕数</th>
                        <th width="100" style="text-align: center;">已装包蛋糕数</th>
                        <th width="100" style="text-align: center;">未装包蛋糕数</th>
                    </tr>
                    </thead>
                    <tbody id="goods_list"></tbody>
                </table>

            </div>

            <div class="search-box" id = "bill_goods_input" style="background:white;border: 0px solid #c9c9c9">
                <div style="position:relative">
                    <form class="form-inline" id="item_form" onsubmit="return false;">
                        <table>
                            <tbody>
                            <tr>
                                <td>
                                    <span><span class="red">*</span>蛋糕条码：<input type="text" class="form-control input-sm" style="width:210px" value="" name="bill_goods_no" id="bill_goods_no" placeholder="请输入订单商品流水号,并按回车键"></span>
                                    <span>装包人：<input type="text" class="form-control input-sm" style="width:180px" value="<!--{$voucher_operator}-->" readonly name="voucher_operator" id="voucher_operator" ></span>
                                    <span id="print_body"><input id="print_id" value="打印冰包标签" onclick="Goods.printIcePackLabel(1);" class="btn btn-default" type="button"></span>
                                </td>
                                <td style="display: none;" id="voiceError"></td>
                                <td style="display: none;" id="multicake"></td>
                            </tr>
                            </tbody>
                        </table>
                    </form>
                </div>
            </div>

            <div class="panel panel-default"  style="display:block;" >
                <table class="table table-bordered" id="logInfo">
                    <thead>
                    <tr >
                        <th width="180" style="text-align: center;" >订单编号</th>
                        <th width="180" style="text-align: center;">商品名称</th>
                        <th width="140" style="text-align: center;">配送站</th>
                        <th width="140" style="text-align: center;">冰包标签</th>
                    </tr>
                    </thead>
                    <tbody id="log_list">
                    </tbody>
                </table>

            </div>
        </div>

</div>
<div  style="height:0px; overflow:hidden;">
    <input type="button" id="hdb">
</div>
<audio id="audio" controls="controls" autoplay="autoplay" style="display: none;"></audio>
<script type="text/javascript">

/*实例打印接口*/
CreateReport("Report");

var Goods = {

    in_pack:0,//已装包蛋糕数
    out_pack:0,//未装包蛋糕数
    bill_goods_no:'',//订单生产流水号
    //查询生成订单商品生产信息
    search: function() {

        $("#goods_list").html('');

        $('#goods_info').html('');//待录入商品信息部分置空

        var send_date = $("#send_date").val();

        if(send_date == ""){
            E.alert("配送日期不能为空");
        }

        var formValues = E.getFormValues("search_form");

        E.ajax_post({
            url: "/invokingAjax-backend/production/icePackGoods.ajax?operFlg=1",
            data:{
                formValues:formValues
            },
            call: "Goods.addLineCallBack" //根据查询信息成功回调函数
        });

        E.ajax_post({
            url: "/invokingAjax-backend/production/icePackGoods.ajax?operFlg=3",
            data:{
                formValues:formValues
            },
            call: "Goods.loadLineCallBack" //根据查询信息成功回调函数
        });

    },
    //查询信息成功回调
    addLineCallBack: function (response){

        if (response.code == 200) {

            var data = response.data;//返回入库单数组
            var billGoodsNum = data.length;
            for(var i=0;i<billGoodsNum;i++){

                Goods.in_pack = data[i].packScan_num;
                Goods.out_pack = data[i].warehouse_num - data[i].packScan_num;

                var html = '<tr class = "trData"  id="goods_line_' + data[i].distribution_id + '">';
                html += '<td style="text-align: center;">' + data[i].distribution_name + '</td>';
                html += '<td style="text-align: center;">' + data[i].warehouse_num + '</td>';
                html += '<td id="in_pack" style="text-align: center;">' + data[i].packScan_num + '</td>';
                html += '<td id="out_pack" style="text-align: center;">' + (data[i].warehouse_num - data[i].packScan_num) + '</td>';
                html += '</tr>';
                $('#goods_list').prepend( html );
            }

            $('#bill_goods_voucher').show();//待录入商品信息部分显示
            $('#bill_goods_no').val('').focus();

        } else {

            $('#bill_goods_voucher').hide();
            E.alert(response.message);

        }

    },
    //查询信息成功回调
    loadLineCallBack: function (response){

        if (response.code == 200) {

            var data = response.data;

            var html = '';

            $.each(data,function(k, v) {

                html += '<tr style="text-align: center;background-color:rgb(0,255,0);" >';
                html += '<td style="text-align: center; ">' + v.bill_code + '</td>';
                html += '<td style="text-align: center; ">' + v.goods_name + '</td>';
                html += '<td style="text-align: center; ">' + v.site_name + '</td>';
                html += '<td style="text-align: center; ">' + v.ice_label + '</td>';
                html += '</tr>';

            });

            $('#log_list').html( html );

        }else{
            $('#log_list').empty();
        }

    },
    //通过订单流水号查询订单
    searchBillGoodsInfo:function( bill_goods_no ){

        var formValues = E.getFormValues("search_form");
        E.ajax_post({
            url: "/invokingAjax-backend/production/icePackGoods.ajax?operFlg=2",
            data:{formValues:formValues,bill_goods_no:bill_goods_no},
            call: "Goods.infoAddLineCallBack"
        });
    },
    //根据条码获取商品信息成功回调
    infoAddLineCallBack: function ( response ){

        if (response.code == 200) { //与头查询条件匹配

            var data = response.data;

            var html = '';

            html += '<tr style="text-align: center;background-color:rgb(0,255,0);" >';
            html += '<td style="text-align: center; ">' + data.bill_code + '</td>';
            html += '<td style="text-align: center; ">' + data.goods_name + '</td>';
            html += '<td style="text-align: center; ">' + data.site_name + '</td>';
            html += '<td style="text-align: center; ">' + data.ice_label + '</td>';
            html += '</tr>';

            $('#logInfo').prepend( html );

            var print_str = '<input id="print_id" value="打印冰包标签" onclick="Goods.printIcePackLabel(1);" class="btn btn-default" type="button">';
            $("#print_body").html(print_str);

            /*定义声音标签*/
            var audio = '<audio controls="controls" autoplay="autoplay"><source src="/quanliadmin/docroot/images/'+data.audio+'" type="audio/ogg">您的浏览器不支持 audio 标签。</audio>';

            /*播放声音*/
            $('#voiceError').html(audio);
        }
        else { //语音报错

            E.alert(response.message);

            if(response.code == 400){
            
            	var item = '<audio controls="controls" autoplay="autoplay"><source src="/report/voice/mismatch_site.wav"  type="audio/ogg">您的浏览器不支持 audio 标签。</audio>';
            
            }else if(response.code == 500){
                var item = '<audio controls="controls" autoplay="autoplay"><source src="/report/voice/send_date_error.wav"  type="audio/ogg">您的浏览器不支持 audio 标签。</audio>';
            }else{
             
             	var item = '<audio controls="controls" autoplay="autoplay"><source src="/report/voice/error.wav"  type="audio/ogg">您的浏览器不支持 audio 标签。</audio>';
            
            }
            
            $('#voiceError').html(item);
            $('#hdb').focus();
        }

        $('#bill_goods_no').val('');

    },
    //取消操作
    removeAddLine:function(){
        $('#goods_line_'+Goods.bill_goods_no).remove();
        $('#bill_goods_no').val('').focus();
    },
    //重新加载
    load:function(){
        E.refresh();
        $('#bill_goods_voucher').hide();//待录入商品信息部分隐藏
    },
    audioPlay: function() {
        var Media = document.getElementById("audio");

        $('#audio').attr('src','/quanliadmin/docroot/images/voicePrompt/multicake.wav');
        Media.play();

        Media.removeEventListener("ended",Goods.audioPlay, false );

    },
    printIcePackLabel:function(status){

        var formValues = E.getFormValues("search_form");

        E.ajax_post({
            url: "/invokingAjax-backend/production/icePackGoods.ajax?operFlg=4&status="+status,
            data:{
                formValues:formValues
            },
            call: function( obj ) {

                if(obj.code == 200){

                    /*加载打印模板*/
                    Report.LoadFromURL('/report/ICE_PACK_LABEL_5.grf');

                    /*加载打印数据*/
                    Report.LoadDataFromURL('/report/prin_ice_pack_label.php?label_code='+obj.data.label_code);

                    /*预览*/
                    //Report.PrintPreview(true);

                    /*直接打印*/
                    Report.Print(false);

                    /*重设打印按钮*/
                    $("#print_body").html('<input id="print_id" value="重新打印冰包标签" onclick="javascript:if(window.confirm(\'你已打印该标签，是否重新打印？\')){Goods.printIcePackLabel(0);}else{return false;}" class="btn btn-default" type="button">');

                    /*重新加载已装包蛋糕数*/
                    var update_num = obj.data.update_num;

                    Goods.in_pack += update_num;

                    Goods.out_pack -= update_num;

                    /*已装包蛋糕数*/
                    var in_pack = $("#in_pack").html(Goods.in_pack);

                    /*已装包蛋糕数*/
                    var out_pack = $("#in_pack").html(Goods.out_pack);

                    /*清除本次扫描结果*/
                    $("#log_list").empty();


                }else{

                    E.alert(obj.message);

                    var item = '<audio controls="controls" autoplay="autoplay"><source src="/report/voice/error.wav"  type="audio/ogg">您的浏览器不支持 audio 标签。</audio>';

                    $('#voiceError').html(item);

                    $('#hdb').focus();
                }
            }
        });
    }
};
//订单流水号回车事件
$("#bill_goods_no").keydown(function(e){
    if(e.keyCode == 13){
        var bill_goods_no = $.trim($("#bill_goods_no").val());
        if(bill_goods_no == ''){
            global_focus = 'bill_no';
            E.alert('请输入订单商品流水号');
            return false;
        }else{
            Goods.searchBillGoodsInfo( bill_goods_no );
        }
    }
});

//日期控件JS
$('#send_date').datepicker();

$(window).ready(function() {

    $("#cityID").html("");

    var cityHtml = '<option value="">请选择</option>';

    $.ajax({
        type: "post",
        url: "/invokingAjax-comm/bill/distribution.ajax?operFlg=1",
        dataType: "json",
        data: "",
        success: function( result_obj ) {
            if(result_obj.code == 200){
                var selected = "";
                if(result_obj.data.length == 1){
                    selected = "selected";
                }
                $.each(result_obj.data, function(i,val){
                    cityHtml +='<option value="'+val.id+'" '+selected+'>'+val.name+'</option>';
                });
                $('#cityID').html(cityHtml);
                $("#cityID").trigger("change");
            }else{
                E.alert(result_obj.message);
            }
        }
    });

    //点击城市联动获得配送站
    $(document).on('change', '#cityID', function() {

        $('#distribution_id').html("");
        $('#distribution_technician_id').html('');

        var cityID = $('#cityID').children('option:selected').val();
        var distributionHtml = '<option value="">请选择</option>';
        var technicianHtml = '<option value="">请选择</option>';
        $.ajax({
            type: "post",
            url: "/invokingAjax-comm/bill/distribution.ajax?operFlg=2",
            dataType: "json",
            data: {deliver_cityid: cityID},
            success: function( obj ) {
                if(obj.code ==200 && obj.data != null){
                    var selected = "";
                    if(obj.data.length == 1){
                        selected = "selected";
                    }
                    $.each(obj.data, function(i,val){
                        distributionHtml +='<option value="'+val.distribution_id+'" '+selected+'>'+val.distribution_name+'</option>';
                    });
                    $('#distribution_id').html(distributionHtml);
                    $('#distribution_technician_id').html(technicianHtml);
                }else{
                    distributionHtml += '';
                    $('#distribution_id').html(distributionHtml);
                    $('#distribution_technician_id').html(technicianHtml);
                }
            }
        });
    });

});

</script>

</body>
</html>